#include "Action.h"
#include "Worker.h"

using namespace kryptos::util;

namespace kryptos { namespace actions {

Action::Action() : _actionProgress(0)
                 , _cancelAction(false)
                 , _actionSucceeded(false)
{
}

Action::~Action()
{
    //Cleanup();
}

void Action::execute()
{
    _worker.reset(new Worker());
    connect(_worker.data(),SIGNAL(started()),this, SLOT(Go()));
    this->moveToThread(_worker.data());
    _worker->start();
}

void Action::cancel()
{
    _cancelAction = true;
}

void Action::Go()
{
    RunAction();
}

void Action::AddAndEmitProgress(int delta)
{
    _actionProgress = (_actionProgress + delta > 100) ? 100 : _actionProgress + delta;
    emit actionProgress(_actionProgress);
}

void Action::SetAndEmitProgress(int absolute)
{
    _actionProgress = absolute > 100 ? 100 : absolute;
    emit actionProgress(_actionProgress);
}

}}
